#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re, math, json, os, datetime;
# ==== 异常 ====
def fun():
    a = 10
    try:
        a = a / 0;
    except ZeroDivisionError as e:
        print(e);
    finally:
        print("必须执行");
    return a;

#== == 类 == ==


class Person(object):
    def __init__(self, id, name, age, sex):
        self.id = id;
        self.name = name;
        self.age = age;
        self.sex = sex;

    def getId(self):
        return self.id;

    def setId(self, id):
        self.id = id;


# ==== Json ====
def json_fun():
    person = Person(1, 'HymanHu', 18, 'male');
    print(person.__dict__);
    print(json.dumps(person.__dict__));
    person_json = '{"id": 2, "name": "HymanHu2", "age": 19, "sex": "male"}';
    person.__dict__ = json.loads(person_json)
    print(person.name);
# ==== 文件操作 ====
    def file_fun():
        # f = None;
        # try:
        #     f = open("D:/temp/temp.txt", "a", encoding="utf-8");
        #     # lines = f.readlines();
        #     # print(lines);
        #     f.write("aaa");
        # except BaseException as e:
        #     print(e);
        # finally:
        #     if f:
        #         f.close();
        with open("D:/temp/temp.txt", "r", encoding="utf-8") as f:
            print(f.readlines());

    def os_fun():
        if not os.path.exists("D:/temp/image"):
            os.mkdir("D:/temp/image");

    if __name__ == '__main__':

        #fun();
        # fun();
        # json_fun();
        # file_fun();
         os_fun();

    

